package com.ruoyi.project.tool.swagger.UserController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysDynamicComment;
import com.ruoyi.project.system.service.ISysDynamicCommentService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户动态评论Controller
 *
 * @author jjp
 * @date 2020-04-16
 */

@RestController
@Api(description = "用户动态评论")
@RequestMapping("/mobileUser/dynamicComment")
public class UserDynamicCommentController extends BaseController {
    @Autowired
    private ISysDynamicCommentService sysDynamicCommentService;

    /**
     * 查询用户动态评论列表
     */

    @GetMapping("/list")
    public TableDataInfo list(SysDynamicComment sysDynamicComment) {
        startPage();
        List<SysDynamicComment> list = sysDynamicCommentService.selectSysDynamicCommentList(sysDynamicComment);
        return getDataTable(list);
    }

    /**
     * 获取用户动态评论详细信息
     */

    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId) {
        return AjaxResult.success(sysDynamicCommentService.selectSysDynamicCommentById(commentId));
    }

    /**
     * 新增用户动态评论
     */

    @Log(title = "用户动态评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDynamicComment sysDynamicComment) {
        sysDynamicComment.setMobileUserId(SecurityUtils.getLoginUser().getSysMobileUser().getMobileUserId());
        return toAjax(sysDynamicCommentService.insertSysDynamicComment(sysDynamicComment));
    }

    /**
     * 修改用户动态评论
     */

    @Log(title = "用户动态评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDynamicComment sysDynamicComment) {
        return toAjax(sysDynamicCommentService.updateSysDynamicComment(sysDynamicComment));
    }

    /**
     * 删除用户动态评论
     */

    @Log(title = "用户动态评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds) {
        return toAjax(sysDynamicCommentService.deleteSysDynamicCommentByIds(commentIds));
    }

    /**
     * 获取用户动态评论详细信息
     */

    @GetMapping(value = "/findDynamicId/{dynamicId}")
    public TableDataInfo findDynamicId(@PathVariable("dynamicId") Long dynamicId) {
        startPage();
        List<SysDynamicComment> list = sysDynamicCommentService.findDynamicId(dynamicId);
        return getDataTable(list);
    }
}